<?= $this->Html->script('autocomplete', array('inline' => false)) ?>

<script type="text/javascript">
var isPrint = parseInt('<?= (int)@$isPrint ?>');
if (isPrint>0) {
    var win = window.open('/orders/aprint/<?= @$data['Order']['id'] ?>', 'printWin');
    win.focus();
}
</script>

<?= $this->Form->create('Order', array('url'=>'/orders/save', 'class'=>'left')) ?>
    <?
        $order = $data['Order'];
        $isNew = empty($order['id']);
        $date_issue = @$order['datum_izdavanja'];
        if (! empty($date_issue)) {
            $date_issue = date('Y-m-d', strtotime($date_issue));
        } else {
            $date_issue = date('Y-m-d');
        }
        $storeId = @$order['store_id'];
        if (! $storeId) {
            $storeId = $this->Session->read('CurrentStore.id');
        }
    ?>
    <?= $this->Form->hidden('id', array('value' => @$order['id'])) ?>
    <?= $this->Form->hidden('user_id', array('value' => $this->Session->read('Auth.User.id'))) ?>
    <?= $this->Form->hidden('store_id', array('value' => $storeId)) ?>
    
    <?= $this->Html->link('&laquo; nazad', '/', array('escape'=>false)) ?>
    
    <?= $this->Form->submit('+ Štampaj', array(
        'div'     => false,
        'type'    => 'button',
        'class'   => 'print right additional',
        'onclick' => "var form=$(this).parent(); form.attr('action', form.attr('action')+'/print:1'); form.submit()"
    )) ?>
    <?= $this->Form->submit('Sačuvaj', array('div' => false, 'class'=>'save right')) ?>
    <? if(! $isNew): ?>
        <?= $this->Form->submit('Obriši', array(
            'div'   => false, 
            'type'  => 'button',
            'class' =>'delete right',
            'onclick' => 'if(confirm(\'Da li želite da obrišete nalog?\')){location.href=\'/orders/delete/'.$order['id'].'\'}'
        )) ?>
    <? endif; ?>
    
    <?= $this->Form->label('datum_izdavanja', 'Datum:') ?>
    <?= $this->Form->text('datum_izdavanja', array('class'=>'datepicker', 'value'=>$date_issue)) ?>
    
    <?= $this->Form->label('musterija_ime', 'Ime i prezime:') ?>
    <?= $this->Form->text('musterija_ime', array('value'=>@$order['musterija_ime'], 'class'=>'medium')) ?>
    <?= $this->Form->select('customer_type_id', array($customerTypes), array(
        'empty' => false,
        'value' => (int)@$order['customer_type_id']
    )) ?>
    
    <?= $this->Form->label('musterija_telefon', 'Telefon:') ?>
    <?= $this->Form->text('musterija_telefon', array('value'=>@$order['musterija_telefon'])) ?>
    
    <?= $this->Form->label('brand_id', 'Marka aparata:') ?>
    <?= $this->Form->text('brand_id', array(
        'value'        => @$data['BrandModel']['Brand']['name'],
        'autocomplete' => 'off',
        'onchange'     => 'var prev=this.getAttribute(\'previous\'); if(this.value!=prev)this.value=prev',
        'onkeyup'      => 'DropListBrands(this,\'OrderBrandId\')'
    )) ?>
    <?= $this->Form->label('brand_model_id', 'Model aparata:', array('class'=>'inline')) ?>
    <?= $this->Form->text('brand_model_id', array(
        'value'        => @$data['BrandModel']['name'],
        'autocomplete' => 'off',
        'onchange'     => 'var prev=this.getAttribute(\'previous\'); if(this.value!=prev)this.value=prev',
        'onkeyup'      => 'DropListModel(this,\'OrderBrandId\',\'OrderBrandModelId\')'
    )) ?>
    
    <?= $this->Form->label('imei', 'IMEI:') ?>
    <?= $this->Form->text('imei', array(
        'value' => @$order['imei'],
        'class' => 'medium',
        'maxlength' => 20
    )) ?><span class="left info input-info">*20 karaktera max.</span>
    
    <?= $this->Form->label('problem', 'Opis problema:') ?>
    <?= $this->Form->textarea('problem', array('value' => @$order['problem'])) ?>
    
    <?= $this->Form->label('baterija', 'Baterija:') ?>
    <?= $this->Form->select('baterija', $flagOptions, array('value'=>(int)$order['baterija'], 'empty'=>false)) ?>
    
    <?= $this->Form->label('punjac', 'Punjač:', array('class'=>'inline')) ?>
    <?= $this->Form->select('punjac', $flagOptions, array('value'=>(int)$order['punjac'], 'empty'=>false)) ?>
    
    <?= $this->Form->label('garancija', 'Garancija:', array('class'=>'inline')) ?>
    <?= $this->Form->select('garancija', $flagOptions, array(
        'value'    =>(int)$order['garancija'], 
        'empty'    =>false,
        'onchange' => 'var el=$(\'#OrderGarancijaOd\');if(this.value>0){el.show()}else{el.hide()}'
    )) ?>
    <?= $this->Form->text('garancija_od', array(
        'value' => @$order['garancija_od'],
        'style' => 'display:' . ((int)$order['garancija']>0 ? 'block' : 'none')
    )); ?>
    
    <div id="EditNalogDIV" style="display:<?= $isNew ? 'none' : 'block' ?>">
        <?= $this->Form->label('cena', 'Cena:') ?>
        <?= $this->Form->text('cena', array('value'=>@$order['cena'])) ?>
        
        <?= $this->Form->label('naplaceno', 'Naplaćeno:') ?>
        <?= $this->Form->text('naplaceno', array('value'=>@$order['naplaceno'])) ?>
        
        <?= $this->Form->label('datum_popravke', 'Popravljeno:') ?>
        <?= $this->Form->text('datum_popravke', array('value'=>date_local(@$order['datum_popravke'],'Y-m-d'), 'class'=>'datepicker')) ?>
        
        <?= $this->Form->label('datum_preuzimanja', 'Preuzeto:') ?>
        <?= $this->Form->text('datum_preuzimanja', array('value'=>date_local(@$order['datum_preuzimanja'],'Y-m-d'), 'class'=>'datepicker')) ?>
    </div>
    
    <?= $this->Form->label('napomena', 'Napomena:') ?>
    <?= $this->Form->textarea('napomena', array('value' => @$order['napomena'])) ?>
    
<?= $this->Form->end() ?>